import requests
from api_demo.ihrm_test import config


class EmpAPI:
    def __init__(self):
        self.url_add_emp = config.BASE_URL + "/api/sys/user"
        self.url_update_emp = config.BASE_URL + "/api/sys/user/{}"
        self.url_select_emp = config.BASE_URL + "/api/sys/user/{}"
        self.url_delete_emp = config.BASE_URL + "/api/sys/user/{}"

    # 添加员工接口
    def add_emp(self, add_emp_data):
        url = self.url_add_emp
        print(config.HEADERS)
        return requests.post(url=url, json=add_emp_data, headers=config.HEADERS)

    # 修改员工接口
    def update_emp(self, update_emp_data, emp_id):
        url = self.url_update_emp.format(emp_id)
        return requests.put(url=url, json=update_emp_data, headers=config.HEADERS)

    # 查询员工接口
    def select_emp(self, emp_id):
        url = self.url_select_emp.format(emp_id)
        return requests.get(url=url, headers=config.HEADERS)

    # 删除员工接口
    def delete_emp(self, emp_id):
        url = self.url_delete_emp.format(emp_id)
        return requests.delete(url=url, headers=config.HEADERS)